package org.example.zrccddllljh.Service.Impl;


import org.example.zrccddllljh.Mapper.AdminMapper;
import org.example.zrccddllljh.Pojo.Admin;
import org.example.zrccddllljh.Service.AdminService;
import org.example.zrccddllljh.utils.Md5Util;
import org.example.zrccddllljh.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin findByUserName(String username) {
        Admin byUserName = adminMapper.findByUserName(username);

        return byUserName;
    }

    @Override
    public void register(String username, String password) {
        String md5String = Md5Util.getMD5String(password);
        adminMapper.add(username,md5String);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        adminMapper.updatePwd(Md5Util.getMD5String(newPwd),id);
    }

    @Override
    public void updateAvatar(String avatarUrl) {
        Map<String,Object> map = ThreadLocalUtil.get();

        Integer id = (Integer) map.get("id");
        adminMapper.updateAvatar(avatarUrl,id);
    }

    @Override
    public void updata(Admin admin) {
        admin.setUpdateTime(LocalDateTime.now());
        adminMapper.updata(admin);
    }

    @Override
    public List<Admin> password(String o) {


        List<Admin> pad = adminMapper.password(o);

        return pad;
    }


}
